package com.sh.personnel.util.result;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 接口数据回调封装类
 * @author Administrator
 * @date 2019/12/14 15:51
 */
@Data
public class Result {

    private Object code; // 状态码
    private String message; // 提示信息

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private Map<String, Object> data = new HashMap<String, Object>(); //返回数据

    public Result(){}
    public Result(Object code, String message) {
        this.code = code;
        this.message = message;
    }
    public Result(Object code, String message, Map<String, Object> data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Result success() {
        return new Result(
                BaseResult.SUCCESS.getCode(),
                BaseResult.SUCCESS.getMessage()
        );
    }
    public static Result success(String message) {
        return new Result(
                BaseResult.SUCCESS.getCode(),
                message
        );
    }
    public static Result fail() {
        return new Result(
                BaseResult.FAIL.getCode(),
                BaseResult.FAIL.getMessage()
        );
    }
    public static Result fail(String message) {
        return new Result(
                BaseResult.FAIL.getCode(),
                message
        );
    }
    public Result setData(String key, Object value) {
        data.put(key, value);
        return this;
    }
}
